import 'package:flutter/material.dart';

class Animated6Page extends StatefulWidget {
  const Animated6Page({super.key});

  @override
  State<Animated6Page> createState() => _AnimatedPagePageState();
}

class _AnimatedPagePageState extends State<Animated6Page>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  bool flag=true;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: Duration(seconds: 1), //持续时间
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          flag?_controller.forward():_controller.reverse();
          flag=!flag;
          //_controller.status == AnimationStatus.completed? _controller.reverse(): _controller.forward();
        },
        child: Icon(Icons.refresh),
      ),
      body: Center(
        child: Stack(
          children: [
            ScaleTransition(
              scale: _controller.drive(Tween(begin: 1.0, end: 0.0).chain(CurveTween(curve: Interval(0, 0.5)))),
              child: Icon(Icons.close, size: 40),
            ),
            ScaleTransition(
              scale: _controller.drive(Tween(begin: 0.0, end: 1.0).chain(CurveTween(curve: Interval(0.5, 1.0)))),
              child: Icon(Icons.search, size: 40),
            ),
          ],
        ),
      ),
    );
  }
}
